package org.example.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {

    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    static{
        Properties props = new Properties();
        try {
            props.load(new FileInputStream("/Users/cengyunke/Desktop/atm1/Ball/src/main/resources/db.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        url = props.getProperty("url");
        username = props.getProperty("username");
        password = props.getProperty("password");
        driver = props.getProperty("driver");
        try {
            Class.forName(driver);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static Connection getConnection() throws SQLException {
        Connection con = DriverManager.getConnection(url,username,password);
        return con;
    }

}
